package com.example.scaffold.common.bean;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {
    private long total;         // 总条数
    private long pages;          // 总页数
    private long pageNum;        // 当前页码
    private long pageSize;       // 每页条数
    private List<T> list;       // 数据列表
    
    public static <T> PageResult<T> of(IPage<T> iPage) {
        PageResult<T> result = new PageResult<>();
        result.setTotal(iPage.getTotal());
        result.setPages(iPage.getPages());
        result.setPageNum(iPage.getCurrent());
        result.setPageSize(iPage.getSize());
        result.setList(iPage.getRecords());
        return result;
    }
}
